#ifndef __DSTH_CODEC_H__
#define __DSTH_CODEC_H__

#include <string>

#include "Connection.h"

using namespace dsth;
using std::string;

struct message_t {
    string to;
    string from;
    string chat_text; 
};

class Codec {
public:
    typedef Acf::Delegate<void (Connection*, message_t*, Timestamp)> MessageHandler;
    typedef Acf::Delegate<void (Connection*, Timestamp)> ErrorHandler;

    void SetMessageHandler(const MessageHandler& handler) { msg_handler_ = handler; }
    void SetErrorHandler(const ErrorHandler& handler) { err_handler_ = handler; }
    void SendMessage(Connection* conn, const message_t& message);
    void OnMessage(Connection* conn, ChannelBuffer* buf, Timestamp time);
private:
    message_t* Parse(const char* data, size_t len);
    ErrorHandler err_handler_;
    MessageHandler msg_handler_;
};

#endif // __DSTH_CODEC_H__